#include <ut/UnitTest.h>
#include <illib/Log.h>
#include <illib/System.h>

using namespace illib;

namespace illib_ut{
	void testMemory(illib::System::Memory &memoryBlock, uint8_t *block, size_t memoryBlockSize){
		uint8_t *ptr = memoryBlock.start();
		ut::test(AT(), EX(memoryBlock.start() == block), TN(illib::Memory::start));
		ut::test(AT(), EX(memoryBlock.start() != 0), TN(illib::Memory::start));
		ut::test(AT(), EX(memoryBlock.end() == block+memoryBlockSize), TN(illib::Memory::start));
		ut::test(AT(), EX(memoryBlock.size() == memoryBlockSize), TN(illib::Memory::number));
		ut::test(AT(), EX(memoryBlock.start()+memoryBlockSize == memoryBlock.end()), TN(illib::Memory::end));
		ut::test(AT(), EX(memoryBlock.contains(ptr, 1)), TN(illib::Memory::contains));
		ut::test(AT(), EX(memoryBlock.contains(ptr+memoryBlockSize-1, 1)), TN(illib::Memory::contains));
		ut::test(AT(), EX(!memoryBlock.contains(ptr+memoryBlockSize, 1)), TN(illib::Memory::contains));
		ut::test(AT(), EX(memoryBlock.contains(ptr+memoryBlockSize, 0)), TN(illib::Memory::contains));
	}

	void System_ut(){
		ut::UnitTestLogger logger(TN(illib_ut::Memory_ut));
		{
			uint8_t memory1[1024];
			System::Memory block1(memory1,sizeof(memory1));
			testMemory(block1, memory1, sizeof(memory1));

			uint8_t memory2[512];
			System::Memory block2(memory2, sizeof(memory2));
			testMemory(block2, memory2, sizeof(memory2));
		}
	}
};
